--
-- Author: ping.wang
-- Date: 2018-07-06 13:45:58
--
-- AuctionController
--

local AuctionView = import("..views.AuctionView")
local AuctionStorageView = import("..views.AuctionStorageView")
local AuctionKeyboardPanel = import("..views.AuctionKeyboardPanel")
local AuctionBuyOrSellView = import("..views.AuctionBuyOrSellView")
local AuctionFilterMenuView = import("..views.AuctionFilterMenuView")
local AuctionNormalBuyView = import("..views.AuctionNormalBuyView")
local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ControllerBase)

local string_find = string.find
local table_insert = table.insert

function ClassRef:ctor(data)
    self.super.ctor(self, data)
end

function ClassRef:init()
    self._model = app:getInst("AuctionModel")
    self._curPageIdx = 1 --当前页
    self._curPageMax = 1 --最大页
    self._currentSelectTabIdx = Enums.AuctionProductType.normal
    self._isSaleOrOffShelves = false --在出售界面是否做过相关操作
    self._curSearchName = nil --当前搜索的名字
    self._searchItemCache = {} --根据当前搜索名字得到的id缓存
end

function ClassRef:removeListeners()
    self.super.removeListeners(self)
end

function ClassRef:onEvent(eventName, data)
end

function ClassRef:listEvent()
    return {}
end

function ClassRef:openView(data)
    self:closeStorageView()
    self:closeView()

    local tabIdx = 1
    if data then
        if data.tipsData then
            tabIdx = data.tipsData:getAcType()
        else
            tabIdx = data and data.tabIdx or 1
        end
    end
    self._currentSelectTabIdx = tabIdx
    if cc.isDead(self._view) then
        self._view = AuctionView.new(app.mvc.VIEWTYPE_BLUR,tabIdx)
        self._view:onCloseView(handler(self, self.closeView))
        self._view:onClearView(handler(self, self.clearView))
        self._view:onOperate(handler(self, self.onOperate))
    end
    self:addChild(self._view, data)
    self._view:show()

    self._auctionProductPanel = self._view:getProductPanel()
    self._auctionProductPanel:onOperate(handler(self, self.onOperate))
    self._auctionProductPanel:initClassify(self._model:getAuctionShopClassifyData())



    if data and data.tipsData then
        --根据tips跳转进来 tipsData是一个itemData 需要跳转到出售界面
        local itemData = data.tipsData
        local firstMenuIdx = 1
        local secondMenuIdx = 1
        if data then
            firstMenuIdx, secondMenuIdx = self._model:getMenuIdxByAuctionType(itemData:getAcType(), itemData:getSubMenu())
        end
        self._auctionProductPanel:setTargetSeleced(firstMenuIdx, secondMenuIdx)

        --准备显示出售界面
        --先请求商品指导价格 再显示出售面板 此时应该转移
        self._isSaleOrOffShelves = false
        self:openStorageView()
        self._model:reqMySaleList()
        self:reqItemSuggestPrice(itemData:getUid(),itemData:getId())
    else
        local curTabIdx = data and data.tabIdx or 1
        local firstMenuIdx = 1
        local secondMenuIdx = 1
        if data then
            firstMenuIdx, secondMenuIdx = self._model:getMenuIdxByAuctionType(data.tabIdx, data.auctionType)
        end
        self._auctionProductPanel:setTargetSeleced(firstMenuIdx, secondMenuIdx)
        self._auctionProductPanel:setSearchName(data and data.searchName or "")
    end
end

function ClassRef:clearView()
    self._view = nil
    self._auctionProductPanel = nil
    self._curPageIdx = 1 --当前页
    self._curPageMax = 1 --最大页
    self._currentSelectTabIdx = Enums.AuctionProductType.normal
    self._isSaleOrOffShelves = false
    self._model:clearAllData() --关掉界面的时候清理掉所有的拍卖行网络数据
    self._curSearchName = nil
    self._searchItemCache = {}
    self._filterListView = nil
    self._buyOrSellView = nil
    self._keyboard = nil
end

function ClassRef:closeView(data)
    if self._view then
        self:removeChild(self._view, data)
        if not cc.isDead( self._buyOrSellView ) then
            UIHandler:removePopupUiByKey("AuctionBuyOrSellView")
        end
        if not cc.isDead( self._filterListView ) then
            UIHandler:removePopupUiByKey("AuctionFilterMenuView")
        end
        self:clearView()
    end
end
---------------打开背包出售界面---------------
function ClassRef:openStorageView()
    if nil == self._auctionStorageView then
        self._auctionStorageView = AuctionStorageView.new(app.mvc.VIEWTYPE_BLUR)
        self._auctionStorageView:onCloseView(handler(self, self.closeStorageView))
        self._auctionStorageView:onClearView(handler(self, self.clearStorageView))
        self._auctionStorageView:onOperate(handler(self, self.onOperate))
    end
    self:addChild(self._auctionStorageView)
    local currentSelectTabIdx = self._view:getCurrentTabId()
    self._auctionStorageView:refreshTitle(currentSelectTabIdx)

    self._auctionStorageView:show()
end

function ClassRef:closeStorageView()
    if self._view and self._auctionStorageView then
        self:removeChild(self._auctionStorageView)
        if self._isSaleOrOffShelves then
            self:_reqProductList() --此时请求刷新下界面
        end
        self._model:clearMySaleGoodsData() --关闭掉我的出售界面的时候 清理掉我的出售数据
    end
    self:clearStorageView()
end

function ClassRef:clearStorageView()
    self._auctionStorageView = nil
end
---------------------------buyOrSellView---------------------------------------------
---对于出售界面 data = {itemData = itemData, suggestPrice = price, isbuy = false}
---对于购买界面 data = {itemData = itemData, isbuy = true, goodData = goodData}
function ClassRef:openBuyOrSellView(data)
    local itemData = data.itemData
    if itemData then
        if cc.isDead( self._buyOrSellView ) then
            self._buyOrSellView = AuctionBuyOrSellView.new()
            self._buyOrSellView:onCloseView(handler(self, self.closeBuyOrSellView))
            self._buyOrSellView:onOperate(handler(self, self.onOperate))
            UIHandler:addPopupUi(self._buyOrSellView,"AuctionBuyOrSellView")
        end

        self:refreshBuyOrSellView(data,data.isbuy)
        self._buyOrSellView:stopAllActions()
        self._buyOrSellView:show()
    end
end
function ClassRef:closeBuyOrSellView()
    if self._buyOrSellView then
        self._buyOrSellView:hide()
    end
end

function ClassRef:refreshBuyOrSellView(data,isBuy)
    if self._buyOrSellView then
        self._buyOrSellView:refreshContent(data,isBuy)
    end
end


---------------------显示普通购买界面----------------------
function ClassRef:openNormalBuyView(data)
    if cc.isDead( self._normalBuyView ) then
        self._normalBuyView = AuctionNormalBuyView.new(app.mvc.VIEWTYPE_BLUR,data)
        self._normalBuyView:onCloseView(handler(self, self.closeNormalBuyView))
        self._normalBuyView:onOperate(handler(self, self.onOperate))
    end
    self:addChild(self._normalBuyView)
    self._normalBuyView:stopAllActions()
    self._normalBuyView:show()
end

function ClassRef:closeNormalBuyView()
    if not cc.isDead( self._normalBuyView ) then
        self:removeChild(self._normalBuyView)
        self._normalBuyView = nil
    end
end

-------------------keyboard-----------------------------
function ClassRef:_openKeyBoard(pos,num,callFunc)
    if cc.isDead( self._keyboard ) then
        self._keyboard = AuctionKeyboardPanel.create()
        self._keyboard:setCallFunc(callFunc)
        self._keyboard:setNum(num)
        self._keyboard:onOperate(handler(self, self.onOperate))
        UIHandler:addPopupUi( self._keyboard,"AuctionKeyboardPanel")
        -- 点击空白区域关闭
        display.nodeRemoveForNotHit(self._keyboard, function()
            if not cc.isDead( self._keyboard ) then
                self._keyboard:performWithDelay(function()
                    UIHandler:removePopupUiByKey("AuctionKeyboardPanel")
                    self._keyboard = nil
                end, 0)
            end
        end)
    end

    self._keyboard:setVisible( true )

    local width = self._keyboard:getContentSize2()
    local posX = pos.x
    if posX + width > display.width then
        posX = display.width - width
    end
    self._keyboard:setPosition( cc.p( posX, pos.y ) )
end

--------------------endkeyboard---------------------------------
function ClassRef:_showFilterList(data)
    if cc.isDead( self._filterListView ) then
        self._filterListView = AuctionFilterMenuView.new()
        self._filterListView:onOperate(handler(self, self.onOperate))
        UIHandler:addPopupUi( self._filterListView,"AuctionFilterMenuView")
    end
    self._filterListView:refresh(data)
    self._filterListView:setVisible(true)
end

---------------刷新我的出售界面----------------------------
function ClassRef:refreshMySale()
    if cc.isDead(self._view) then
        return
    end

    local currentSelectTabIdx = self._view:getCurrentTabId()
    if not cc.isDead(self._auctionStorageView) then

        if currentSelectTabIdx == Enums.AuctionProductType.normal then
            self._auctionStorageView:refresh({bagItemData = self._model:getAllItemsCanSell(),saleGoods = self._model:getMySaleNormalGoods(), isNormal = true})
        else
            self._auctionStorageView:refresh({bagItemData = self._model:getAllItemsCanSell(),saleGoods = self._model:getMySaleBidGoods(), isNormal = false})
        end

    else
        self._model:setProductList(currentSelectTabIdx,self._model:getMySaleNormalGoods(),self._model:getMySaleBidGoods())
        self:refreshAuctionProductList()
    end
end
------------------打开出售界面之前需要获取商品的指导价----------------
------目前先每次打开的时候请求一个id，之后再优化----------------
function ClassRef:reqItemSuggestPrice(uuid,itemId)
    self._model:reqQueryGoodsAveragePrice(uuid,itemId)
end

---------------------------商品上架----------------------
function ClassRef:reqOnShelves(uuid,price,count,fixedPrice)
    --要判断货架是否足够
    --print(uuid,price,count,fixedPrice)
    local shelvesLimite = GD:getSystemPar( "auctionShelvesLimite",0) --获取货架最大数量
    local curSellCount = 0
    if fixedPrice then
        curSellCount = #self._model:getMySaleBidGoods()
    else
        curSellCount = #self._model:getMySaleNormalGoods()
    end

    if curSellCount < tonumber(shelvesLimite) then
        self._model:reqOnShelves(uuid,price,count,fixedPrice)
    else
        display.pushToast(L("auction_tips5"))
    end
end

-------------------------商品下架------------------------------
function ClassRef:reqOffShelves(goodData)
    local itemData = goodData:getItemData()
    local uuid = goodData:getProductUUId()
    if itemData:getAcType() == Enums.AuctionProductType.bid and goodData:hasBiding() then
        --判断是否有人已经竞价过
        display.pushToast(L("tips_2000021"))
    else
        self._model:reqOffShelves(uuid)
    end
end

--在下架成功后刷新界面
function ClassRef:refreshAfterOffShelves()
    if not cc.isDead(self._auctionStorageView) then
        self._model:reqMySaleList()
    else
        self:_reqProductList()
    end
end

-------------------------本地列表下架商品不用请求服务器------------------------
function ClassRef:localOffShelves(uuid)
    local currentSelectTabIdx = self._view:getCurrentTabId()
    self._model:removeMySaleProduct(uuid,currentSelectTabIdx == Enums.AuctionProductType.bid)
    self:refreshMySale()
end

---------------------刷新拍卖行主界面上的显示列表------------------
function ClassRef:refreshAuctionProductList()
    if cc.isDead(self._view) then
        return
    end

    --这里只管把数据传递给UI 怎么显示 怎么分页都是UI自己的事
    local everyPageNum = GD:getSystemPar("auctionListNum") --每页显示多少条数据
    local totalNums = self._model:getTotalGoodsCount() --总的数量 用来计算显示的最大页数

    self._curPageMax = math.ceil(totalNums/everyPageNum) --最大页
    if self._curPageMax == 0 then self._curPageMax = 1 end

    if self._curPageIdx > self._curPageMax then --如果显示页面大于最大页 则改为最大页，其中显示当前页是在调用显示的时候设定的
        self._curPageIdx = self._curPageMax
    end

    local showData = self:_getCurrentPageProductDataList(self._curPageIdx)

    if showData then
        local isLastPage = self._model:isLastPage()
        local isNotUseTotalCount = self._model:isNotUseTotalCount()
        --当前页，最大页，显示数据
        self._view:refreshProductPanel({curPageIdx = self._curPageIdx,curPageMax = self._curPageMax, productList = showData, isLastPage = isLastPage, isNotUseTotalCount = isNotUseTotalCount})
    else

        display.pushToast(L("后面没有拍卖品了"))
    end
end

------根据当前的页面来获得应该显示的数据 调用此函数的时候确保已经从服务器拉到当前显示的数据
function ClassRef:_getCurrentPageProductDataList(curPageIdx)
    local showProductList = self:_getCurShowProductList()

    local everyPageNum = GD:getSystemPar("auctionListNum") --每页显示多少条数据
    local curBeginPageIdx = self._model:getCurBeginPageIdx() --服务器传递过来的数据是从第几页开始显示的
    --print(everyPageNum,curBeginPageIdx)
    if curPageIdx >= curBeginPageIdx then
        local startProductIdx = (curPageIdx - curBeginPageIdx) * everyPageNum + 1
        local endProductIdx = startProductIdx + everyPageNum - 1
        if endProductIdx > #showProductList then
            endProductIdx = #showProductList
        end
        local returnData = {}
        --print(startProductIdx,endProductIdx)
        for i = startProductIdx,endProductIdx do
            table.insert(returnData,showProductList[i])
        end

        return returnData
    else
        print("curPageIdx < curBeginPageIdx is error ",curPageIdx,curBeginPageIdx)
    end
end

--获取当前页面上显示所用的数据集
function ClassRef:_getCurShowProductList()
    if not cc.isDead(self._view) then
        local currentSelectTabIdx = self._view:getCurrentTabId()
        if currentSelectTabIdx == Enums.AuctionProductType.bid then
            return self._model:getBidingGoods()
        else
            return self._model:getNormalGoods()
        end
    end
end

-----------------前往某一页---------------
function ClassRef:_startShowPage(idx)
    local everyPageNum = GD:getSystemPar("auctionListNum") --每页显示多少条数据
    --获取现在服务器发送了多少条数据
    local showProductList = self:_getCurShowProductList()

    local curBeginPageIdx = self._model:getCurBeginPageIdx() --服务器传递过来的数据是从第几页开始显示的
    local curEndPageIdx = curBeginPageIdx + math.ceil(#showProductList/everyPageNum) - 1 --获取服务器传递过来的数据到第几页结束
    --取得最大页数和最小页数
    local minPageIdx = 1
    
    --local isLastPage = self._model:isLastPage()
    local isNotUseTotalCount = self._model:isNotUseTotalCount()

    if isNotUseTotalCount then

        if idx < minPageIdx then self._curPageIdx = minPageIdx end
        self._curPageIdx = idx
        --判断当前是否有名字搜索 有走搜索消息 否则 走普通查询消息
        if self._curSearchName then
            self:_sendSearchItems()
        else
            --只有类型选择为全部的时候才需需要向服务器发送刷新
            if self._auctionProductPanel:getTypeFilterValue() == Enums.AuctionFilterType.all then
                self:_reqProductList()
            end
        end
    else
        local maxPageIdx = math.ceil(self._model:getTotalGoodsCount()/everyPageNum)
        if maxPageIdx == 0 then maxPageIdx = 1 end
        --在最大最小范围内进行翻页 判断当前页面的数据本地是否有 没有则请求服务器刷新
        if idx >= minPageIdx and idx <= maxPageIdx then
            self._curPageIdx = idx --设置当前页数
            if idx < curBeginPageIdx or idx > curEndPageIdx then

                --判断当前是否有名字搜索 有走搜索消息 否则 走普通查询消息
                if self._curSearchName then
                    self:_sendSearchItems()
                else
                    --只有类型选择为全部的时候才需需要向服务器发送刷新
                    if self._auctionProductPanel:getTypeFilterValue() == Enums.AuctionFilterType.all then
                        self:_reqProductList()
                    end
                end
            else
                --不用请求 更新显示数据即可
                if not self._curSearchName then
                    self:_resetSearchNameCache()
                end
                local showData = self:_getCurrentPageProductDataList(self._curPageIdx)
                self._view:refreshProductPanel({curPageIdx = self._curPageIdx,curPageMax = self._curPageMax, productList = showData})
            end
        end
    end
end


--请求显示当前过滤条件下的拍卖行数据
--kind 商品类型（1：普通商品，2：竞价商品)
--pages 页数(0：表示请求所有商品信息，单次请求上限50条;如果页数超限，返回最后一页)
function ClassRef:_reqProductList()
    if cc.isDead(self._view) then
        return
    end

    self:_resetSearchNameCache()
    local classifyId = self._auctionProductPanel:getCurSelectedClassifyId()
    if classifyId then
        local conditionData = self._auctionProductPanel:getFilterConditions()
        if conditionData.typeFilter == Enums.AuctionFilterType.all then
            conditionData.pages = self._curPageIdx
            conditionData.kind = self._view:getCurrentTabId()
            self._model:reqQuerySaleList(conditionData.kind,conditionData.sub_menu,conditionData.quality,conditionData.bidding_price_asc,conditionData.pages,conditionData.my_use_lv)

        elseif conditionData.typeFilter == Enums.AuctionFilterType.mySold then
            self._model:reqMySaleList()
        elseif conditionData.typeFilter == Enums.AuctionFilterType.myBid then
            self._model:reqMyBidingList()
        end
    end
end
-----------------购买普通商品--------------------
function ClassRef:_reqBuyNormalProducts(data)
    self._model:reqBuyNormalGoods(data[1],data[2])
    self:closeBuyOrSellView()
end

function ClassRef:_reqBuyNormalFixedProducts(data)
    self._model:reqBuyNormalFixedGoods(data[1],data[2])
    self:closeNormalBuyView()
end

--买完界面需要刷新 无论成功与否
function ClassRef:refreshAfterBuyProducts()
    self:_reqProductList()
end


----------------购买竞价商品----------------------
----data={uuid,price}
--一口价
function ClassRef:_reqFixedBuyBidProducts(data)
    --判断钱是否足够
    local coinId = 99
    local publisher = app:getInnerPublisher()
    if publisher == Enums.Publisher.tencent then
        coinId = tonumber(GD:getSystemPar( "auctionBiddingGoodsLootType_tencent",99))
    else
        coinId = tonumber(GD:getSystemPar( "auctionBiddingGoodsLootType",115))
    end
   
    local money = UD:getDaibiValue(coinId)
    if money >= data[2] then
        self._model:reqBuyBidGoods(data[1],data[2])
        self:closeBuyOrSellView()
    else
        local coinConfig = GD:getCoinConfig(coinId)
        display.pushToast(string.format(L("auction_tips9"),L(coinConfig.name)))
    end
end

--加价
--data = {goodData,price}
function ClassRef:_reqBuyBidProducts(data)
    local coinId = 99
    local publisher = app:getInnerPublisher()
    if publisher == Enums.Publisher.tencent then
        coinId = tonumber(GD:getSystemPar( "auctionBiddingGoodsLootType_tencent",99))
    else
        coinId = tonumber(GD:getSystemPar( "auctionBiddingGoodsLootType",115))
    end
    local money = UD:getDaibiValue(coinId)
    --判断这件商品是否是我出价的
    local goodData = data[1]
    local pId = goodData:getProductUUId()
    local ret = goodData:isMeTheMaxBiddingPrice()

    local needJudgePrice = data[2]
    if ret then
        needJudgePrice = needJudgePrice - goodData:getMyBiddingPrice()
    end

    if money >= needJudgePrice then
        self._model:reqBuyBidGoods(pId,data[2])
        self:closeBuyOrSellView()
    else
        local coinConfig = GD:getCoinConfig(coinId)
        display.pushToast(string.format(L("auction_tips9"),L(coinConfig.name)))
    end
end

-----------------------名字模糊搜索----------------------
---名字模糊搜索遇到 条件变更 或者 输入名字为空的情况下，名字搜索则重置为空 不起作用

--在切换了搜索子菜单 以及过滤条件后 都要重置名字搜索的缓存
function ClassRef:_resetSearchNameCache()
    if self._auctionProductPanel then
        self._auctionProductPanel:resetSearchName()
    end
    self._curSearchName = nil
    self._searchItemCache = {}
end


function ClassRef:_searchProductsByName(name)
    if name == "" then
        self:_resetSearchNameCache()
        self:_reqProductList()
        return
    end

    --if self._curSearchName ~= name then
        self._curSearchName = name
        --此时才需要先通过名字搜索本地的表 获知哪些itemid符合条件
        local subMenuId = self._auctionProductPanel:getCurSelectedClassifyId()

        self._searchItemCache = self:_getAllItemIdsByName(name,subMenuId)
        --dump(self._searchItemCache)
        self._curPageIdx = 1
        self:_sendSearchItems()
    --end
end

--是否是全部类型
function ClassRef:isAllType(subMenu)
    return subMenu == 1110 or subMenu == 2110
end


--通过名字和子分类过滤ID
function ClassRef:_getAllItemIdsByName(name,subMenu)
    local allItems = GD:queryItems()
    local allJewels = GD:queryJewels()
    local allEquips = GD:queryEquips()
    local cacheIds = {}


    local currentSelectTabIdx = self._view:getCurrentTabId()
    --dump(currentSelectTabIdx)

    for k,v in ipairs(allItems) do
        --判断名字是否符合
        if tonumber(v.subMenu) == subMenu and string_find(L(v.name),name) and tonumber(v.acType) ==  currentSelectTabIdx then
            table_insert(cacheIds,tonumber(v.ID))
        end
    end

--[[
    for k,v in ipairs(allJewels) do
        --判断名字是否符合
        if (tonumber(v.subMenu) == subMenu  or self:isAllType(subMenu)) and string_find(L(v.name),name) then
            table_insert(cacheIds,tonumber(v.ID))
        end
    end
--]]
    for k,v in ipairs(allEquips) do
        --判断名字是否符合
        if (tonumber(v.subMenu) == subMenu  or self:isAllType(subMenu)) and tonumber(v.acType) ==  currentSelectTabIdx and string_find(L(v.string),name) then
            table_insert(cacheIds,tonumber(v.ID))
        end
    end
    --dump(cacheIds)
    return cacheIds
end

--向服务器发送搜索消息
function ClassRef:_sendSearchItems()
    if self._curSearchName and self._searchItemCache then
        if #self._searchItemCache > 0 then
            local currentSelectTabIdx = self._view:getCurrentTabId()
            local isShowMyLv = self._auctionProductPanel:isOnlyShowMyLv()
            local subMenuId = self._auctionProductPanel:getCurSelectedClassifyId()
            local priceFilter = self._auctionProductPanel:getPriceFilter()
            self._model:reqSearchItemsByName(currentSelectTabIdx,subMenuId,self._searchItemCache,self._curPageIdx,isShowMyLv,priceFilter)
        else
            display.pushToast(L("tips_1990063"))
        end
    end
end

--排序显示当前的内容-------------
function ClassRef:_sortGoodsByPrice(isUpper)
    --[[
    local currentSelectTabIdx = self._view:getCurrentTabId()
    if currentSelectTabIdx == Enums.AuctionProductType.normal then
        self._model:sortNormalGoodsByPrice(isUpper)
    else
        self._model:sortBiddingGoodsByPrice(isUpper)
    end

    self:refreshAuctionProductList()
    ]]

    self:_reqProductList()
end

function ClassRef:getCurrentSelectTabIdx()
    return self._currentSelectTabIdx
end

function ClassRef:_refreshClassify()
    self._auctionProductPanel:initClassify(self._model:getAuctionShopClassifyData())
    self._auctionProductPanel:setTargetSeleced(1,1)
end


----收到服务器普通购买商品信息----------
function ClassRef:refreshNormalBuyView(goodsList)
    if cc.isDead(self._normalBuyView) then return end
    self._normalBuyView:refreshList(goodsList)
end
-------------------------------------------------------
function ClassRef:onOperate(op, data)
    print("AuctionController:onOperate op = " .. op)
    if op == "selectedTarget" then
        self._curPageIdx = 1
        self:_reqProductList()
    elseif op == "changeFilter" then
        self._curPageIdx = 1
        self:_reqProductList()
    elseif op == "changeFilterMyLv" then
        --搜索符合自己等级的
        if self._curSearchName then
            self:_sendSearchItems()
        else
            self._curPageIdx = 1
            self:_reqProductList()
        end
    elseif op == "changeFilterMySell" then
        --过滤显示我的出售
        self:_resetSearchNameCache()
        self._curPageIdx = 1
        self._model:reqMySaleList()
    elseif op == "changeFilterMyBid" then
        --过滤显示我的竞价
        self:_resetSearchNameCache()
        self._curPageIdx = 1
        self._model:reqMyBidingList()
    elseif op == "priceFilter" then
        self._curPageIdx = 1
        self:_reqProductList()
        --self:_sortGoodsByPrice(data == Enums.AuctionFilterSoldPrice.lower)
    elseif op == "showFilterList" then
        --显示过滤的下拉条
        self:_showFilterList(data)
    elseif op == "showPrePage" then
        --上一页
        self:_startShowPage(self._curPageIdx - 1)
    elseif op == "showNextPage" then
        --下一页
        self:_startShowPage(self._curPageIdx + 1)
    elseif op == "showProductPanelByTabIdx" then
        --根据当前选中的tabidx显示相关的界面  普通商品 或 竞价商品
        self._currentSelectTabIdx = data
        self._curPageIdx = 1
        --self:_reqProductList()
        self:_refreshClassify()
    elseif op == "openSalePanel" then
        --先请求商品指导价格 再显示出售面板 此时应该转移
        self._isSaleOrOffShelves = false
        self:openStorageView()
        self._model:reqMySaleList()
    elseif op == "localOffShelves" then
        --本地下架商品 不用请求服务器 仅限于哪些时间到期的自动刷新
        self._isSaleOrOffShelves = true
        self:localOffShelves(data)
    elseif op == "pullOffItem" then
        --下架商品
        self._isSaleOrOffShelves = true
        self:reqOffShelves(data)
    elseif op == "offerItem" then
        --显示购买界面
        local itemData = data:getItemData()
        if itemData:getAcType() == 1 then
            --此处要判断道具是否是可以堆叠的类型 决定显示哪一种购买界面
            local subMenuId = self._auctionProductPanel:getCurSelectedClassifyId()
            local subMenuInfo = GD:queryAuctionshopById(subMenuId)
            if tonumber(subMenuInfo.goodType) == 1 then
                self:openNormalBuyView({itemData=itemData, goodData = data})
                self._model:reqQueryNormalGoodsList(itemData:getId(),subMenuId)
            else
                self:openBuyOrSellView({itemData=itemData, isbuy = true, goodData = data})
            end
        else
            self:openBuyOrSellView({itemData=itemData, isbuy = true, goodData = data})
        end
    elseif op == "showSoldWin" then
        --准备向服务器发送消息获取该商品的指导售价
        local itemData = data
        self:reqItemSuggestPrice(itemData:getUid(),itemData:getId())
    elseif op == "showMiniKeyboard" then
        --显示小键盘
        self:_openKeyBoard(data[1],data[2],data[3])
    elseif op == "closeMiniKeyboard" then
        if not cc.isDead( self._keyboard ) then
            self._keyboard:removeFromParent(true)
            self._keyboard = nil
        end
    elseif op == "startBuy" then
        --需要ID 和 数量 普通购买
        self:_reqBuyNormalProducts(data)
    elseif op == "startBuyFixed" then
        self:_reqBuyNormalFixedProducts(data)
    elseif op == "fixedBuy" then
        --一口价购买
        self:_reqFixedBuyBidProducts(data)
    elseif op == "bidBuy" then
        --出价
        self:_reqBuyBidProducts(data)
    elseif op == "normalSell" then
        --普通出售
        self._isSaleOrOffShelves = true
        self:reqOnShelves(data[1],data[2],data[3],nil)
        self:closeBuyOrSellView()
    elseif op == "bidSell" then
        --竞价出售
        self._isSaleOrOffShelves = true
        self:reqOnShelves(data[1],data[2],data[3],data[4])
        self:closeBuyOrSellView()
    elseif op == "updateNormalBuyNum" then
        --普通商品购买刷新数量
        self._normalBuyView:refreshListByData(data)
    elseif op == "searchProductByName" then
        --通过名字搜索商品
        --print(data)
        if app:isNeedCheckInput() then
            app:checkInput(data, function(response,errorMsg,code)
                if code == 200 then
                    if response and response.result then
                        self:_searchProductsByName(data)
                    else
                        display.pushToast(L("lua_code_text_11"))
                    end
                else
                    display.pushToast(L("network_error"))
                end
            end)
        else
            self:_searchProductsByName(data)
        end
    end
end

return ClassRef
